﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.CacheService.CacheProvider.LocalCache;
using A2DFramework.CacheService.Configuration;

namespace A2DFramework.CacheService.Coordinator.Wrappers
{
    public class CacheServerWrapper : ICacheExecutor
    {
        ICacheExecutor executor = null;
        private CacheServerInfo configInfo;
        public CacheServerWrapper(CacheServerInfo configInfo)
        {
            this.configInfo = configInfo;
            ICacheExecutor tmpExecutor = null;
            switch(this.configInfo.ServerType)
            {
                case CacheServerType.Memcache:
                    tmpExecutor = new CacheProvider.MemcachedCacheProvider(configInfo);
                    break;
                case CacheServerType.Redis:
                    tmpExecutor = new CacheProvider.RedisCacheProvider(configInfo);
                    break;
            }
            executor = tmpExecutor;
        }

        public string FullServerAddress
        {
            get
            {
                return this.configInfo.FullServerAddress;
            }
        }

        public void Put(string key, object value, CacheExpireType expireType, double increment)
        {
            executor.Put(key, value, expireType, increment);
        }

        public object Get(string key)
        {
            return executor.Get(key);
        }

        public void Remove(string key)
        {
            executor.Remove(key);
        }
    }
}
